﻿using MVVMLightDemo.interfaces;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using Ninject;

namespace MVVMLightDemo.Implements
{
    public class NinjectContainer : IServiceContainer
    {
        StandardKernel _kernel;

        public NinjectContainer()
        {
            _kernel = new StandardKernel();
        }
        
        public void Add<TInterface, TService>() where TService : TInterface
        {
            _kernel.Bind<TInterface>().To<TService>();
        }

        public void AddSingleton<TInterface>(TInterface implement)
        {
            _kernel.Bind<TInterface>().ToConstant(implement).InSingletonScope();    
        }

        public void AddSingleton<TInterface, TService>() where TService : TInterface
        {
            _kernel.Bind<TInterface>().To<TService>().InSingletonScope();
        }

        public bool Contains<T>()
        {
            return _kernel.CanResolve<T>();
        }

        public object GetServices(Type t)
        {
            return _kernel.Get(t);
        }

        public TInterface GetServices<TInterface>()
        {
            return _kernel.Get<TInterface>();
        }
    }
}
